{block name=table-payments}
{if $payments }
	<div id="orders-list">
		<div class="panel-group" id="accordion">
			{foreach $payments as $payment}
			{assign var='hasPending' value=0}
			{foreach $payment.debt as $debt}{if $debt.payment_id && $debt.debt_paid_date}{else}{assign var='hasPending' value=$debt.debt_id}{break}{/if}{/foreach}
			<div class="panel panel-default">
				<div class="panel-heading{if $hasPending gt 0} bg-gray{/if}">
					<h4 class="panel-title">
						<a data-toggle="collapse" data-parent="" href="#{$payment.payment_id}"> 
							<span>
								<b>订单号:</b> {$payment.payment_transaction_no} | <b>创建日期:</b> {$payment.cart_closed_date|date_format:"%d %b %Y"}
							</span>
							<!-- {assign var='hasTrial' value=0}
							{foreach $payment.items as $item}
								{if $item.cartitem_enrolment_type eq 'T'}{assign var='hasTrial' value=1}{/if}
							{/foreach} -->
							<span class="pull-right text-{if $payment.status_order lt 50}success{else}danger{/if}"><b>{$payment.status_name}</b></span>
							<!-- {if $hasTrial eq 1}
							<span class="pull-right marg-5r">Trial |</span>
							{/if} -->
						</a>
					</h4>
				</div>
				<div id="{$payment.payment_id}" class="panel-collapse collapse {if $request.cartid eq $payment.payment_cart_id}in{/if}">
					<div class="panel-body">
						<div class="text-right">
							{if $admin.level eq 1}
								{if $payment.status_id eq 7 || $payment.status_id eq 8} 
									<a href="/admin/members/change-payment-method/{$payment.payment_id}" class="btn btn-info">修改支付方式</a>
								{/if}
								<a href="/admin/edit/orders/{$payment.payment_cart_id}" class="btn btn-black top-btn">修改状态</a>
							{/if}
						</div>
						<table class="top-margin" cellspacing="0" width="100%" cellpadding="0" border="0">
							<tr align="left">
								<th>项目</th>
								<th class="text-right">数量</th>
								<th style="min-width:65px;" class="text-right">单价</th>
								<th style="min-width:70px;" class="text-right">总价</th>
							</tr>
							{foreach $payment.items as $item}
							<tr valign="top" aling="left">
								{assign var=free value=0}
								<td>
									<a href="{$item.url}" target="_blank">
										{if $item.cartitem_product_gst eq '0'}{assign var=free value=1} *{/if}
											{if $item.cartitem_custom_type}{$item.cartitem_custom_type}: {/if}{$item.cartitem_product_name} 
											{if $item.attributes}
											{assign var='hasweek' value=0}
											{foreach from=$item.attributes item=attr name=attributesarr}
												{if $item.cartitem_class_flag eq 1 && $item.cartitem_enrolment_type eq 'T' } 
													<b>[ 日期: {getdatebyweekdaystartdate weekday=$item.class_weekday startdate=$item.term_start_date weeksafter=$item.attributes.0.cartitem_attr_attr_value_name-1 dateformat='d/m/Y'} ]</b>
												{else}
													{if $item.cartitem_product_id gt 0}
														{if $attr.cartitem_attr_attribute_name eq 'week'}
															{if $hasweek eq 0}
																/ 周: 
																{assign var='hasweek' value=1}
															{/if}
															{$attr.cartitem_attr_attr_value_name} {if !$smarty.foreach.attributesarr.last}|{/if}
														{else}
															 / {$attr.cartitem_attr_attribute_name}: {$attr.cartitem_attr_attr_value_name}
														{/if}
													{/if}
												{/if}
											{/foreach}
										{/if}
									</a>
								</td>
								<td width="10%" class="text-right">{$item.cartitem_quantity}</td>
								<td width="20%" class="text-right">{$CURRENCY_SYMBOL}{$item.cartitem_product_price|number_format:2:".":","}</td>
								<td width="20%" class="text-right">{$CURRENCY_SYMBOL}{$item.cartitem_subtotal|number_format:2:".":","}</td>
							</tr>
							{/foreach}
							<tr valign="top" align="left">
								<td colspan="4"><hr></td>
							</tr>
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>小计</strong></td>
								<td style="text-align: right">{$CURRENCY_SYMBOL}{$payment.payment_subtotal|number_format:2:".":","}</td>
							</tr>
							{if $payment.payment_discount neq '0.00'}
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>优惠</strong></td>
								<td class="text-right">{$CURRENCY_SYMBOL}-{$payment.payment_discount|number_format:2:".":","}</td>
							</tr>
							{/if}
							{if $payment.payment_shipping_fee neq '0.00'}
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>Shipping</strong></td>
								<td style="text-align: right">{$CURRENCY_SYMBOL}{$payment.payment_shipping_fee|number_format:2:".":","}</td>
							</tr>
							{/if}
							{if $payment.payment_additional neq '0.00'}
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>{$payment.payment_additional_description}</strong></td>
								<td class="text-right">{$CURRENCY_SYMBOL}{$payment.payment_additional|number_format:2:".":","}</td>
							</tr>
							{/if}
							<tr valign="top" align="left">
								<td>{if $free}(*){$TAX_CODE} free item.{/if}</td>
								<td colspan="2" class="text-right"><strong>包含  {$TAX_CODE}</strong></td>
								<td style="text-align: right">({$CURRENCY_SYMBOL}{$payment.payment_gst|number_format:2:".":","})</td>
							</tr>
							{if $payment.payment_surcharge neq '0.00'}
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>Credit card surcharge</strong></td>
								<td class="text-right">{$CURRENCY_SYMBOL}{$payment.payment_surcharge|number_format:2:".":","}</td>
							</tr>
							{/if}
							<tr valign="top" align="left">
								<td colspan="4"><hr></td>
							</tr>
							<tr valign="top" align="left">
								<td colspan="3" class="text-right"><strong>总计</strong></td>
								<td style="text-align: right"><strong>{$CURRENCY_SYMBOL}{$payment.payment_total|number_format:2:".":","}</strong></td>
							</tr>
							<tr valign="top" align="left">
								<td colspan="4"><hr></td>
							</tr>
							{if count($payment.debt) gt 0}
								{if $payment.payment_charged_amount neq $payment.payment_total}
								<tr valign="top" align="left">
									<td colspan="3" class="text-right"><strong>Initial payment [{$payment.payment_created|date_format:"%Y-%m-%d"}] - {$payment.payment_response_cardscheme}</strong></td>
									<td style="text-align: right"><strong>{$CURRENCY_SYMBOL}{$payment.payment_charged_amount|number_format:2:".":","}</strong></td>
								</tr>
								{/if}
							{foreach $payment.debt as $debt}
								{if $debt.payment_id && $debt.debt_paid_date}
								<tr valign="top" align="left">
									<td colspan="3" class="text-right"><strong>Payment [{$debt.debt_paid_date|date_format:"%Y-%m-%d"}] - {$debt.payment_response_cardscheme}</strong></td>
									<td style="text-align: right"><strong>{$CURRENCY_SYMBOL}{$debt.payment_charged_amount|number_format:2:".":","}</strong></td>
								</tr>
								{else}
								<tr valign="top" align="left" class="text-danger">
									<td colspan="3" class="text-right"><strong>Pending payment [{$debt.debt_nextpayment_date|date_format:"%Y-%m-%d"}]</strong></td>
									<td style="text-align: right"><strong>{$CURRENCY_SYMBOL}{$debt.debt_amount|number_format:2:".":","}</strong></td>
								</tr>
								{/if}
							{/foreach}
							<tr valign="top" align="left">
								<td colspan="4"><hr></td>
							</tr>
							{/if}
						</table>
						{if $hasPending gt 0}
							<div class="text-right">
								<a href="/admin/members/make-payment/{$user.user_id}?debt_id={$hasPending}" class="btn btn-warning">Make payment</a>
							</div>
						{/if}
					</div>
				</div>
			</div>
			{/foreach}
		</div>
	</div>
{else}
	<div class="member-tab-content">
 		没有付款记录。
 	</div> 
{/if}

{/block} 


